package com.zlop.cloud.business.ribbon.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RestController
public class UserController {
	
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Value("${server.port}")
	private String serverPort;
	
	@Autowired
	private RestTemplate restTemplate;
	
	@GetMapping("/listUsersByRibbon")
	@HystrixCommand(fallbackMethod = "listUsersByRibbonFallback")
    public String listUsersByRibbon(){
		logger.info("===call trace-1===");
		String result = restTemplate.getForObject("http://zlop-cloud-business-api/listUsers", String.class);
		return result;
	}
	
	public String listUsersByRibbonFallback() {
		return "listUsersByRibbon异常，端口：" + serverPort;
	}

}
